Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of extend and block in EJS #142

Closed
wants to merge 4 commits into from
Closed

Conversation

ictliujie
Copy link

@visionmedia, fyi:
Add features of extend and block, which could support
(1) multilayer inheritance, fully support layout in EJS.
(2) Also could work with include.
The examples and test has also been add!

add features of extend and block, could support multilayer inheritance,
could fully support the layout in EJS. Also could work with include. The
examples and test has also been add!
the test in benchmark shows that the layout using extend is 33% faster
than that using include
@rafaizidoro
Copy link

+1

@welkang
Copy link

welkang commented Nov 23, 2013

How to use the extend and block feature?

@welkang
Copy link

welkang commented Nov 23, 2013

Oh, I found it.
Extend file with <%+ file-to-be-extended %>
Blocks <%block blockname%>content comes here<%/block%>, cooperate with extend

@ictliujie
Copy link
Author

@welkang, yes, that is the way. You could also refer to the examples in the source code. Have fun

@onurozkan
Copy link

+1



//the extend symbol must be in the first place of the file if exist
if(str.trim().indexOf(open + "+") == "0"){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest looks fine and the tests are good but we'd definitely want to try and make this chunk more declarative it's not super obvious and it's a lot to cram into the one function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right. I used too many temp variables in the function. I'll spend my weekend to optimize the code, make it more declarative. we can talt about it later.
The extend feature is very useful and necessary. So I advise strongly that it could be merged into the trunk sooner or later. thanks!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also #147 which is similar, it would be great if you could maybe check out that PR and help review :D at a glance they both look really similar

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'd like to :D

reorganize the code related to extend , make it more declarative
@AdamPuzio
Copy link

I am excited about this feature returning to EJS, but I'd like to point out that 'extend' and 'layout' are really two different features. With 'layout', you are requesting that the entire content of the current view be wrapped in a particular view. With 'extend', you are instead defining certain blocks that will override the corresponding blocks in the extended view. While possible to do with both, generally extended views can stack many generations deep, while layouts typically don't. While I would love to see both features in EJS, I think it's important to recognize the commonalities and differences between them. Both this and #147 seem to be describing 'extend', but #147 refers to it as 'layout'.

Also, while I'm here, I may as well mention a feature with 'extend' that I've seen (and love) in other template engines: the ability to supplement content in a block, either by explicitly defining 'prepend' or 'append' in the tag or by defining a sub-tag within the block that defines where the ancestor's content should live.

@ictliujie
Copy link
Author

yes, I agree that extend and layout are two different features. And in practice,
(1) we usually use the feature of extend to implement the layout
(2) I don't recommend that multi-layer extend in EJS(or any other template engine), evet if it has been supported. Actually 2-3 layers is enough, which is more clear and efficient.
(3) prepend & append are good features in extend. Considering the great Filter functions in EJS has come up to the two features, I don't realize them in extend.
@AdamPuzio

@mostly-magic
Copy link

@AdamPuzio You're right, #147 is describing "extend" as well. My use of the term layout is just my own improper use of terminology. I'll try to stop that to avoid confusion :-).

I don't see the layout feature you describe as anything more than a specialized use case of extend. I agree with @ictliujie that I don't typically recommend more than 2-3 layers in extend, though maybe your needs do call for it.

I like the idea of prepend/append, and @ictliujie notion of using Filters seems promising. I'll give it some thought for #147. @visionmedia Is this something you would want in an initial launch of templates?

@rafaizidoro
Copy link

Any news on this?

@caspervonb
Copy link

+1

@visionmedia plans to merge this?

@ilanbiala
Copy link

+1

3 similar comments
@sjlu
Copy link

sjlu commented May 27, 2014

+1

@hburrows
Copy link

+1

@richgong
Copy link

richgong commented Jun 5, 2014

+1

@ilanbiala
Copy link

@visionmedia It's been a while since EJS has received any development attention. Are you going to allow people to start taking over this project or is EJS dying?

@richgong
Copy link

Hey guys. I found the extend and block feature I wanted here: https://github.com/RandomEtc/ejs-locals
Just do: npm install ejs-locals
layout = extend
block = block

@flipflopsimsommer
Copy link

@freeauto is the also a block append / prepend feature?
i'm looking for it since weeks.

@Vadorequest
Copy link

@ilanbiala I see many pull request waiting for months. I'm going to find another template node module, EJS is clearly not good enough, there is not even what are the basics for me, coming from Ruby I have the feeling that I can't work with EJS.

@mde
Copy link
Collaborator

mde commented Jul 19, 2014

@Vadorequest, I am the new maintainer of this module, and I hope to get things moving a bit faster once I've familiarized myself more with the codebase.

I am also the maintainer of the Geddy Web app framework for Node (http://geddyjs.org/), which has its own bundled EJS implementation (https://github.com/geddy/geddy/blob/master/lib/template/engines/ejs.js) that also has a couple of features missing here. I hope you'll be patient and give me a chance to ramp up.

As far as "being from the Ruby world," EJS is almost precisely the same as ERB, which was the default in Rails for years. (I haven't followed to see if they've switched to HAML recently or not.)

@Vadorequest
Copy link

@mde Nice! Do you have any idea about what you will start to add/fix in EJS?

@mebibou
Copy link

mebibou commented Sep 20, 2014

+1

@JeffSpies
Copy link

Very interested in this particular functionality. +1

Just to add to the discussion https://github.com/gett/pejs does some of this as well.

@ilanbiala
Copy link

@Vadorequest @mde nothing's moved since May 1st, when TJ made the last commit. I've pretty much moved away from EJS, and there are plenty of other template engines out there.

@Vadorequest
Copy link

Yeah... I keep an eye on it but I don't have much faith in EJS I have to
say. That's really bad because that's the default template engine of
Sails.js, a great framework and because I've worked with it deep into my
architecture and don't want to change everything, but it doesn't work
correctly so ... Just borring. Hate working with stuff that doesn't work
correctly...

@calidion
Copy link

what is the progress on this?

@huxia
Copy link

huxia commented Apr 17, 2017

guys, here is my block implementation for the new ejs.
mde/ejs#252

@rossrossp
Copy link

Is anything happening with this?

@MohitKumar1991
Copy link

Has this support been added ?

@mde
Copy link
Collaborator

mde commented Jul 7, 2017

This version of EJS is no longer maintained. The current version, installable via NPM, is here: https://github.com/mde/ejs

@mde mde closed this Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet